package com.fau.cm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

import com.fau.cm.util.SystemConfig;


/**
 * @desc  来电明细表
 * @author liy
 * @datetime 2014年10月15日,上午11:55:03
 */
@Entity
@Table(name = "medical_call_caller")
public class MedicalCallCaller implements Serializable, JSONAware{
	
	private static final long serialVersionUID = -7422502594898638087L;

	private String id;				// 来电明细表id
	private String serialNum;		// 编号
	private String outsideNum;		// 外线号码
	private String callerNum;		// 呼入电话号码
	private Date callerTime;		// 呼叫时间
	private Date answerTime;		// 接通时间
	private String phoneExtNum;		// 分机号码
	private String whetherAnswer;	// 是否接听
	private Integer callLength;		// 呼叫时长
	private String answerSeat;		// 接听坐席
	private Integer ordersCount;	// 订单数
	private String province;		// 地址省
	private String city;			// 地址市
	private String hospitalId;		// 医院企业id
	
	private Date startTime;			// 开始时间
	private Date endTime;			// 开始时间
	private String ids;				// 多个id
	
	private Date leastCall;			// 最近呼入、开始时间
	private Date firstCall;			// 最早呼入、截至时间
	private Integer answerCount;	// 接起次数
	private Integer callCount;		// 呼入次数、总进线数
	private String repeatCallCount;	// 重复进线数
	private String noRepeatCallCount;// 不重复进线数
	private String seatName;		// 坐席名称
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	@Column(name = "serial_num", length = 50)
	public String getSerialNum() {
		return serialNum;
	}
	
	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}
	
	@Column(name = "outside_num", length = 20)
	public String getOutsideNum() {
		return outsideNum;
	}
	
	public void setOutsideNum(String outsideNum) {
		this.outsideNum = outsideNum;
	}
	
	@Column(name = "caller_num", length = 20)
	public String getCallerNum() {
		return callerNum;
	}
	
	public void setCallerNum(String callerNum) {
		this.callerNum = callerNum;
	}
	
	@Column(name = "caller_time")
	public Date getCallerTime() {
		return callerTime;
	}
	
	public void setCallerTime(Date callerTime) {
		this.callerTime = callerTime;
	}
	
	@Column(name = "answer_time")
	public Date getAnswerTime() {
		return answerTime;
	}

	public void setAnswerTime(Date answerTime) {
		this.answerTime = answerTime;
	}

	@Column(name = "phone_ext_num", length = 20)
	public String getPhoneExtNum() {
		return phoneExtNum;
	}
	
	public void setPhoneExtNum(String phoneExtNum) {
		this.phoneExtNum = phoneExtNum;
	}
	
	@Column(name = "whether_answer", length = 5)
	public String getWhetherAnswer() {
		return whetherAnswer;
	}
	
	public void setWhetherAnswer(String whetherAnswer) {
		this.whetherAnswer = whetherAnswer;
	}
	
	@Column(name = "call_length", length = 11)
	public Integer getCallLength() {
		return callLength;
	}
	
	public void setCallLength(Integer callLength) {
		this.callLength = callLength;
	}
	
	@Column(name = "answer_seat", length = 32)
	public String getAnswerSeat() {
		return answerSeat;
	}
	
	public void setAnswerSeat(String answerSeat) {
		this.answerSeat = answerSeat;
	}
	
	@Column(name = "orders_count", length = 11)
	public Integer getOrdersCount() {
		return ordersCount;
	}
	
	public void setOrdersCount(Integer ordersCount) {
		this.ordersCount = ordersCount;
	}
	
	@Column(name = "province", length = 32)
	public String getProvince() {
		return province;
	}
	
	public void setProvince(String province) {
		this.province = province;
	}
	
	@Column(name = "city", length = 32)
	public String getCity() {
		return city;
	}
	
	public void setCity(String city) {
		this.city = city;
	}
	
	@Column(name = "hospital_id", length = 32)
	public String getHospitalId() {
		return hospitalId;
	}

	public void setHospitalId(String hospitalId) {
		this.hospitalId = hospitalId;
	}

	@Transient
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@Transient
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Transient
	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	@Transient
	public Date getLeastCall() {
		return leastCall;
	}

	public void setLeastCall(Date leastCall) {
		this.leastCall = leastCall;
	}

	@Transient
	public Date getFirstCall() {
		return firstCall;
	}

	public void setFirstCall(Date firstCall) {
		this.firstCall = firstCall;
	}

	@Transient
	public Integer getAnswerCount() {
		return answerCount;
	}

	public void setAnswerCount(Integer answerCount) {
		this.answerCount = answerCount;
	}

	@Transient
	public Integer getCallCount() {
		return callCount;
	}

	public void setCallCount(Integer callCount) {
		this.callCount = callCount;
	}

	@Transient
	public String getRepeatCallCount() {
		return repeatCallCount;
	}

	public void setRepeatCallCount(String repeatCallCount) {
		this.repeatCallCount = repeatCallCount;
	}

	@Transient
	public String getNoRepeatCallCount() {
		return noRepeatCallCount;
	}

	public void setNoRepeatCallCount(String noRepeatCallCount) {
		this.noRepeatCallCount = noRepeatCallCount;
	}
	
	@Transient
	public String getSeatName() {
		return seatName;
	}

	public void setSeatName(String seatName) {
		this.seatName = seatName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("serialNum", serialNum);
		obj.put("outsideNum", outsideNum);
		obj.put("callerNum", callerNum);
		if(callerTime != null){
			obj.put("callerTime", DateFormatUtils.format(callerTime,"yyyy-MM-dd HH:mm:ss"));
		}
		if(answerTime != null) {
			obj.put("answerTime",  DateFormatUtils.format(answerTime,"yyyy-MM-dd HH:mm:ss"));
		}
		obj.put("phoneExtNum", phoneExtNum);
		if(SystemConfig.MEDICAL_ANSWERED_TYPE.equals(whetherAnswer)){
			obj.put("whetherAnswer", "已接起");
		}
		if(SystemConfig.MEDICAL_NO_ANSWER_TYPE.equals(whetherAnswer)){
			obj.put("whetherAnswer", "未接起");
		}
		obj.put("whetherAnswerText", whetherAnswer);
		obj.put("callLength", callLength);
		obj.put("answerSeat", answerSeat);
		obj.put("ordersCount", ordersCount);
		obj.put("province", province);
		obj.put("city", city);
		if(null != leastCall){
			obj.put("leastCall", DateFormatUtils.format(leastCall, "yyyy-MM-dd HH:mm:ss"));
		}
		if(null != firstCall){
			obj.put("firstCall", DateFormatUtils.format(firstCall, "yyyy-MM-dd HH:mm:ss"));
		}
		obj.put("answerCount", answerCount);
		obj.put("callCount", callCount);
		obj.put("repeatCallCount", repeatCallCount);
		obj.put("noRepeatCallCount", noRepeatCallCount);
		obj.put("seatName", seatName);
		return obj.toString();
	}
}
